package com.ruoyi.jiajia.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaFaq;
import com.ruoyi.system.service.IJiajiaFaqService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常见问题Controller
 * 
 * @author knd
 * @date 2021-10-13
 */
@Controller
@RequestMapping("/jiajia/faq")
public class JiajiaFaqController extends BaseController
{
    private String prefix = "jiajia/faq";

    @Autowired
    private IJiajiaFaqService jiajiaFaqService;

    @RequiresPermissions("jiajia:faq:view")
    @GetMapping()
    public String faq()
    {
        return prefix + "/faq";
    }

    /**
     * 查询常见问题列表
     */
    @RequiresPermissions("jiajia:faq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaFaq jiajiaFaq)
    {
        startPage();
        List<JiajiaFaq> list = jiajiaFaqService.selectJiajiaFaqList(jiajiaFaq);
        return getDataTable(list);
    }

    /**
     * 导出常见问题列表
     */
    @RequiresPermissions("jiajia:faq:export")
    @Log(title = "常见问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaFaq jiajiaFaq)
    {
        List<JiajiaFaq> list = jiajiaFaqService.selectJiajiaFaqList(jiajiaFaq);
        ExcelUtil<JiajiaFaq> util = new ExcelUtil<JiajiaFaq>(JiajiaFaq.class);
        return util.exportExcel(list, "常见问题数据");
    }

    /**
     * 新增常见问题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存常见问题
     */
    @RequiresPermissions("jiajia:faq:add")
    @Log(title = "常见问题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaFaq jiajiaFaq)
    {
        return toAjax(jiajiaFaqService.insertJiajiaFaq(jiajiaFaq));
    }

    /**
     * 修改常见问题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaFaq jiajiaFaq = jiajiaFaqService.selectJiajiaFaqById(id);
        mmap.put("jiajiaFaq", jiajiaFaq);
        return prefix + "/edit";
    }

    /**
     * 修改保存常见问题
     */
    @RequiresPermissions("jiajia:faq:edit")
    @Log(title = "常见问题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaFaq jiajiaFaq)
    {
        return toAjax(jiajiaFaqService.updateJiajiaFaq(jiajiaFaq));
    }

    /**
     * 删除常见问题
     */
    @RequiresPermissions("jiajia:faq:remove")
    @Log(title = "常见问题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaFaqService.deleteJiajiaFaqByIds(ids));
    }
}
